/*
 * @Author: your name
 * @Date: 2022-01-22 15:21:47
 * @LastEditTime: 2022-01-22 15:21:47
 * @LastEditors: your name
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \创作平台\admin\src\utils\convertUnit.js
 */
function changeByte(limit) {
    var size = "";
    if (limit < 1 * 1024) {
        //小于1KB，则转化成B
        size = limit.toFixed(2) + "B";
    } else if (limit < 1 * 1024 * 1024) {
        //小于1MB，则转化成KB
        size = (limit / 1024).toFixed(2) + "KB";
    } else if (limit < 1 * 1024 * 1024 * 1024) {
        //小于1GB，则转化成MB
        size = (limit / (1024 * 1024)).toFixed(2) + "MB";
    } else {
        //其他转化成GB
        size = (limit / (1024 * 1024 * 1024)).toFixed(2) + "GB";
    }

    var sizeStr = size + ""; //转成字符串
    var index = sizeStr.indexOf("."); //获取小数点处的索引
    var dou = sizeStr.substr(index + 1, 2); //获取小数点后两位的值
    if (dou == "00") {
        //判断后两位是否为00，如果是则删除00
        return sizeStr.substring(0, index) + sizeStr.substr(index + 3, 2);
    }
    return size;
}
export default changeByte;